const express = require("express")
const {con,getMysql} = require('../../mysql/mysql.js'); 
const user = express.Router() //创建路由


//获取用户信息
user.get("/getauthor",async (req,res)=>{
    let {id}=req.query
let str=`select * from user where id=${id}`
let data=await getMysql(str)
// console.log(data[0].author)
res.send({author:data[0].author})
})


//跟新用户信息
user.get("/userinformation",async (req,res)=>{
    // res.send(req.query)
    let {username,password,author,headerimg}=req.query
    // res.send(username)
    let arr=[username,password,author,headerimg,username]

    let str1="select * from user where username=?"
    let arr1=[username]
    let data1=await getMysql(str1,arr1)
    // console.log(data1)
    if(data1[0].password===password){
             //修改数据
        let str="update user set username=?,password=?,author=?,headerimg=? where username=?"
        let data=await getMysql(str,arr)
        res.send({status:200,data:"修改成功"})
    }else{
        res.send({status:404,data:"修改失败"})
    }
})

module.exports = user

